import {Component} from '@angular/core';
import { BreakpointObserver, Breakpoints, BreakpointState } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import {ActivatedRoute} from "@angular/router";
import {LoggerService} from "@ngx-toolkit/logger";
import {AuthService} from "../../common/service/auth/auth.service";
import {AuthInfo} from "../../common/entity/auth.entity";

@Component({
  selector: 'nav',
  templateUrl: './nav.component.html',
  styleUrls: ['./nav.component.scss']
})
export class NavComponent{

  isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
    .pipe(
      map(result => result.matches)
    );

  constructor(
    private breakpointObserver: BreakpointObserver,
    private activatedRoute: ActivatedRoute,
    private authService: AuthService,
    private logger: LoggerService) {
    this.activatedRoute.data.subscribe((data: { authInfo: AuthInfo }) => {
      this.logger.info(data);
      //这里不知道为什么authInfo的key值为0而不是"authInfo"
      this.authService.authInfo = data["0"];
      this.logger.info(this.authService.authInfo);
    });
  }

  logout():void{
    this.authService.clearAuthInfo();
  }

}
